<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
<!--      <el-form-item label="用户id" prop="userId">-->
<!--        <el-input-->
<!--          v-model="queryParams.userId"-->
<!--          placeholder="请输入用户id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item label="车辆号码" prop="carNo">
        <el-input
          v-model="queryParams.carNo"
          placeholder="请输入车辆号码"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
<!--      <el-form-item label="车辆品牌id" prop="carBrandId">-->
<!--        <el-input-->
<!--          v-model="queryParams.carBrandId"-->
<!--          placeholder="请输入车辆品牌id"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="排量" prop="displacement">-->
<!--        <el-input-->
<!--          v-model="queryParams.displacement"-->
<!--          placeholder="请输入排量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="电池容量" prop="batteryCapacity">-->
<!--        <el-input-->
<!--          v-model="queryParams.batteryCapacity"-->
<!--          placeholder="请输入电池容量"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="续航里程" prop="range">-->
<!--        <el-input-->
<!--          v-model="queryParams.range"-->
<!--          placeholder="请输入续航里程"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="车架号" prop="vehicleIdentifyNo">-->
<!--        <el-input-->
<!--          v-model="queryParams.vehicleIdentifyNo"-->
<!--          placeholder="请输入车架号"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="最高时速" prop="maxSpeed">-->
<!--        <el-input-->
<!--          v-model="queryParams.maxSpeed"-->
<!--          placeholder="请输入最高时速"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="加速时间" prop="accelerationTime">-->
<!--        <el-input-->
<!--          v-model="queryParams.accelerationTime"-->
<!--          placeholder="请输入加速时间"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="车辆参数" prop="modelParameters">-->
<!--        <el-input-->
<!--          v-model="queryParams.modelParameters"-->
<!--          placeholder="请输入车辆参数"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="能耗说明" prop="energyConsumptionDesc">-->
<!--        <el-input-->
<!--          v-model="queryParams.energyConsumptionDesc"-->
<!--          placeholder="请输入能耗说明"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
<!--      <el-form-item label="其它说明" prop="otherDesc">-->
<!--        <el-input-->
<!--          v-model="queryParams.otherDesc"-->
<!--          placeholder="请输入其它说明"-->
<!--          clearable-->
<!--          @keyup.enter.native="handleQuery"-->
<!--        />-->
<!--      </el-form-item>-->
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['charge:charge_car_info:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['charge:charge_car_info:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['charge:charge_car_info:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['charge:charge_car_info:export']"
        >导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="charge_car_infoList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="主键id" align="center" prop="id" />
      <el-table-column label="用户id" align="center" prop="userId" />
      <el-table-column label="车辆号码" align="center" prop="carNo" />
      <el-table-column label="车辆品牌id" align="center" prop="carBrandId" />
      <el-table-column label="燃料类型" align="center" prop="fuelType" #default="scp">
        <span v-if="scp.row.fuelType==0">汽油</span>
        <span v-if="scp.row.fuelType==1">柴油</span>
      </el-table-column>
      <el-table-column label="排量" align="center" prop="displacement" />
      <el-table-column label="车辆照片" align="center" prop="avatarImg" width="100">
        <template slot-scope="scope">
          <image-preview :src="scope.row.avatarImg" :width="50" :height="50"/>
        </template>
      </el-table-column>
      <el-table-column label="电磁类型" align="center" prop="electromagneticType" #default="scp">
        <span v-if="scp.row.electromagneticType==0">电磁辐射</span>
        <span v-if="scp.row.electromagneticType==1">电磁干扰</span>
        <span v-if="scp.row.electromagneticType==2">电磁感应</span>
        <span v-if="scp.row.electromagneticType==3">电磁材料</span>
      </el-table-column>
      <el-table-column label="电池容量" align="center" prop="batteryCapacity" />
      <el-table-column label="续航里程" align="center" prop="ranges" />
      <el-table-column label="车架号" align="center" prop="vehicleIdentifyNo" />
      <el-table-column label="最高时速" align="center" prop="maxSpeed" />
      <el-table-column label="加速时间" align="center" prop="accelerationTime" />
      <el-table-column label="车辆参数" align="center" prop="modelParameters" />
      <el-table-column label="能耗说明" align="center" prop="energyConsumptionDesc" />
      <el-table-column label="其它说明" align="center" prop="otherDesc" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['charge:charge_car_info:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['charge:charge_car_info:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改汽车对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="500px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-form-item label="用户id:" prop="userId">
          <el-input v-model="form.userId" placeholder="请输入用户id" />
        </el-form-item>
        <el-form-item label="车辆号码:" prop="carNo">
          <el-input v-model="form.carNo" placeholder="请输入车辆号码" />
        </el-form-item>
        <el-form-item label="车辆品牌id:" prop="carBrandId">
          <el-input v-model="form.carBrandId" placeholder="请输入车辆品牌id" />
        </el-form-item>
        <el-form-item label="燃料类型:" prop="fuelType">
          <el-input v-model="form.fuelType" placeholder="请输入燃料类型 0汽油 1柴油" />
        </el-form-item>
        <el-form-item label="排量:" prop="displacement">
          <el-input v-model="form.displacement" placeholder="请输入排量" />
        </el-form-item>
        <el-form-item label="车辆照片:" prop="avatarImg">
          <image-upload v-model="form.avatarImg"/>
        </el-form-item>
        <el-form-item label="电磁类型:" prop="electromagneticType">
          <el-input v-model="form.electromagneticType" placeholder="请输入电磁类型 0电磁辐射 1电磁干扰 2电磁感应3电磁材料" />
        </el-form-item>
        <el-form-item label="电池容量:" prop="batteryCapacity">
          <el-input v-model="form.batteryCapacity" placeholder="请输入电池容量" />
        </el-form-item>
        <el-form-item label="续航里程:" prop="ranges">
          <el-input v-model="form.ranges" placeholder="请输入续航里程" />
        </el-form-item>
        <el-form-item label="车架号:" prop="vehicleIdentifyNo">
          <el-input v-model="form.vehicleIdentifyNo" placeholder="请输入车架号" />
        </el-form-item>
        <el-form-item label="最高时速:" prop="maxSpeed">
          <el-input v-model="form.maxSpeed" placeholder="请输入最高时速" />
        </el-form-item>
        <el-form-item label="加速时间:" prop="accelerationTime">
          <el-input v-model="form.accelerationTime" placeholder="请输入加速时间" />
        </el-form-item>
        <el-form-item label="车辆参数:" prop="modelParameters">
          <el-input v-model="form.modelParameters" placeholder="请输入车辆参数" />
        </el-form-item>
        <el-form-item label="能耗说明:" prop="energyConsumptionDesc">
          <el-input v-model="form.energyConsumptionDesc" placeholder="请输入能耗说明" />
        </el-form-item>
        <el-form-item label="其它说明:" prop="otherDesc">
          <el-input v-model="form.otherDesc" placeholder="请输入其它说明" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listCharge_car_info, getCharge_car_info, delCharge_car_info, addCharge_car_info, updateCharge_car_info } from "@/api/charge/charge_car_info";

export default {
  name: "Charge_car_info",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 汽车表格数据
      charge_car_infoList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        userId: null,
        carNo: null,
        carBrandId: null,
        fuelType: null,
        displacement: null,
        avatarImg: null,
        electromagneticType: null,
        batteryCapacity: null,
        ranges: null,
        vehicleIdentifyNo: null,
        maxSpeed: null,
        accelerationTime: null,
        modelParameters: null,
        energyConsumptionDesc: null,
        otherDesc: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        createTime: [
          { required: true, message: "录入时间不能为空", trigger: "blur" }
        ]
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询汽车列表 */
    getList() {
      this.loading = true;
      listCharge_car_info(this.queryParams).then(response => {
        this.charge_car_infoList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        userId: null,
        carNo: null,
        carBrandId: null,
        fuelType: null,
        displacement: null,
        avatarImg: null,
        electromagneticType: null,
        batteryCapacity: null,
        range: null,
        vehicleIdentifyNo: null,
        maxSpeed: null,
        accelerationTime: null,
        modelParameters: null,
        energyConsumptionDesc: null,
        otherDesc: null,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加汽车";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getCharge_car_info(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改汽车";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateCharge_car_info(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addCharge_car_info(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除汽车编号为"' + ids + '"的数据项？').then(function() {
        return delCharge_car_info(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('charge/charge_car_info/export', {
        ...this.queryParams
      }, `charge_car_info_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
